<html>
	<head>
		<meta charset='utf-8'>
		<title>Lifetime Supply</title>
		<script type="text/javascript">
			function calculateSupply(snack,age,maxAge){
				var date=new Date();
				var year=date.getFullYear();
				var restante=maxAge-age;
				var bisiesto=0;

				for(var i=1; i<=restante; i++){
					if((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0))){
						bisiesto++;
					}
					year++;
				}
				var dias=(bisiesto*366)+((restante-bisiesto)*365);
				var total=(snack*dias);
				var bigTotal=Math.round(total);

				if(bigTotal<total){
					bigTotal+=1;
				}
				alert("Años bisiestos: "+bisiesto+ " Años normalitos: "+(restante-bisiesto)+" Años que va a vivir: "+restante+"\nYou will need $"+bigTotal+" to last you until the ripe old age of "+maxAge);
			}
		</script>
		<style type="text/css">
			html,body{
    			height: 100%;
			}
			body{
			   	display: table; 
   				margin: 0 auto;
			}
			div.Principal{
				display: table-cell;   
    			vertical-align: middle;
			}
			div.row{
				display: table-row;
			}
			div.cell{
				display: table-cell;
			}
			div.table{
				display: table;
			}
		</style>
	</head>
	<body>
		<div class='principal'>
			<h1>"Lifetime supply" of your favorite snack</h1>
			<form>
				<div class='table'>
					<div class='row'>
						<div class='cell'><label>Amount spent in snack per day: </label></div>
						<div class='cell'><input type='text' id='snack' value=''></div>
					</div>
					<div class='row'>
						<div class='cell'><label>Age: </label></div>
						<div class='cell'><input type='text' id='age' value=''></div>
					</div>
					<div class='row'>
						<div class='cell'><label>Max Age: </label></div>
						<div class='cell'><input type='text' id='maxAge' value=''></div>
					</div>
				</div><br>
				<input type='button' value='¡Calcular!' onClick="calculateSupply(document.getElementById('snack').value,document.getElementById('age').value,document.getElementById('maxAge').value);">
			</form>
		</div>
	</body>
</html>